<template>
  <div id="app">
    <!-- <h1>根组件 - {{ $store.state.title }} - {{ $store.state.count }}</h1> -->
    <h1>根组件 - {{ title }} - {{ count }}</h1>
    <button @click="addCount(1)">值 + 1</button>
    <button @click="changeCountAction(8888)">1秒后改成8888</button>
    <div>{{ filterList }}</div>
    <br>
    <!-- 访问模块中的state -->
    <div>{{ userInfo.name }}</div>
    <button @click="setUser({name: 'xiaoli', age: 80 })">更新个人信息</button>
    <button @click="setUserSecond({name: 'xwx1439956', age: 30 })">1秒后更新个人信息</button>

    <div>{{ theme }} - {{ desc }}</div>
    <button @click="setTheme('orange')">更新个人信息</button>

    <!-- 访问模块中的getters -->
    <div>{{ upperCaseName }}</div>
    <input type="text">
    <Son1></Son1>
    <br />
    <Son2></Son2>
  </div>
</template>

<script>
import Son1 from './components/Son1.vue'
import Son2 from './components/Son2.vue'
// 辅助函数
import { mapState, mapMutations, mapActions, mapGetters } from 'vuex'

export default {
  name: 'app',
  components: { Son1, Son2 },
  data () {
    return {
    }
  },
  computed: {
    // mapState和mapGetters都是映射属性
    ...mapGetters(['filterList']),
    // 展开运算符自动映射
    ...mapState(['count', 'title']),

    // 需要开启命名空间
    ...mapState('user', ['userInfo']),
    ...mapState('setting', ['theme', 'desc']),

    ...mapGetters('user', ['upperCaseName'])
  },
  created () {
    console.log(this.$store.state.title)
  },
  methods: {
    // mapMutations和mapActions都是映射方法
    ...mapActions(['changeCountAction']),
    ...mapMutations(['addCount']),

    // 分模块的映射
    ...mapMutations('setting', ['setTheme']),
    ...mapMutations('user', ['setUser']),

    ...mapActions('user', ['setUserSecond'])
  }
}
</script>

<style>
#app {
  width: 600px;
  margin: 20px auto;
  border: 3px solid #ccc;
  border-radius: 3px;
  padding: 10px;
}
</style>
